package com.example.red_tea_house.moudle.SystemSetting.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.red_tea_house.R;
import com.example.red_tea_house.entity.setRecyclerViewNameBean;
import com.example.red_tea_house.moudle.SystemSetting.View.SystemSettingActivity;


import org.jetbrains.annotations.NotNull;

import java.util.List;

public class SystemSettingAdapter extends RecyclerView.Adapter<SystemSettingAdapter.SystemSettingViewHolder> {
    private List<setRecyclerViewNameBean> data;
    private Context context;
    private View view;
    private SystemSettingActivity systemSettingActivity;


    public SystemSettingAdapter(List<setRecyclerViewNameBean> data, Context context, SystemSettingActivity systemSettingActivity){
        this.data=data;
        this.context =context;
        this.systemSettingActivity=systemSettingActivity;
    }

    @NonNull
    @Override
    public SystemSettingAdapter.SystemSettingViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType){
        view= LayoutInflater.from(context).inflate(R.layout.setting_item,parent,false);
        return new SystemSettingAdapter.SystemSettingViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull @NotNull SystemSettingAdapter.SystemSettingViewHolder holder, int position) {
        holder.textView.setText(data.get(position).getName());
    }


    @Override
    public int getItemCount() {
        return data == null ? 0 : data.size();
    }

    public class SystemSettingViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
        TextView textView;

        public SystemSettingViewHolder(@NonNull View itemView){
            super(itemView);
            textView=view.findViewById(R.id.item_system);
            itemView.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            systemSettingActivity.turnPage(textView.getText().toString());
        }
    }
}
